<template>
	<view class="container">
		<view class="" style="font-size: 26px;letter-spacing: 1px;m margin: 20px 0;text-align: center;">智慧城市</view>
		<view class="" style="display: flex;align-items: center;margin-top: 20px;">
			<view class="tag">账号：</view>
			<uni-easyinput v-model="user.userName" placeholder="请输入账号" />
		</view>
		<view class="" style="display: flex;align-items: center;margin-top: 20px;">
			<view class="tag">密码：</view>
			<uni-easyinput v-model="user.password" type="password" placeholder="请输入密码" />
		</view>
		<view class="" style="display: flex;align-items: center;margin-top: 20px;">
			<view class="tag">昵称：</view>
			<uni-easyinput v-model="user.nickName" placeholder="请输入昵称" />
		</view>
		<view class="" style="display: flex;align-items: center;margin-top: 20px;">
			<view class="tag">手机号码：</view>
			<uni-easyinput type="number" maxlength="11" v-model="user.phonenumber" placeholder="请输入手机号码" />
		</view>
		<view class="" style="display: flex;align-items: center;margin-top: 20px;">
			<view class="tag">性别：</view>
			<radio-group name="" @change="change">
				<label>
					<radio value="0" :checked="user.sex==0" /><text>男</text>
				</label>
				<label style="margin-left: 10px;">
					<radio value="1" :checked="user.sex==1" /><text>女</text>
				</label>
			</radio-group>
		</view>
		<view class="" @click="to" style="padding: 15px 0;text-align: center;">已有账号去登录</view>
		<button type="primary" @click="submit" style="margin-top: 0px;">注册</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					"userName": "",
					"nickName": "",
					"password": "",
					"phonenumber": "",
					"sex": "0",
				}
			};
		},
		onLoad(item) {

		},
		onReady() {

		},
		onShow() {

		},
		methods: {
			change(e) {
				this.user.sex = e.detail.value
			},
			to() {
				uni.navigateTo({
					url: 'index',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			submit() {
				this.post('/prod-api/api/register', this.user).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
					if (res.code === 200) {
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							});
						}, 400);
					}

				})
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: white;
	}

	.tag {
		width: 5em;
	}
</style>
